<template>
  <div class="udemy-courses-page">
    <!-- 英雄区域 - Udemy风格 -->
    <div class="hero-section">
      <div class="hero-container">
        <div class="hero-content">
          <h1 class="hero-title">学习新技能，提升职业发展</h1>
          <p class="hero-subtitle">从编程基础到高级技术，找到适合您的课程</p>
          <div class="hero-search">
            <div class="search-container">
              <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <circle cx="11" cy="11" r="8"></circle>
                <path d="m21 21-4.35-4.35"></path>
              </svg>
              <input 
                type="text" 
                placeholder="您想学什么？" 
                class="hero-search-input"
                v-model="searchParams.keyword"
                @keyup.enter="searchCourses"
              >
              <button class="hero-search-btn" @click="searchCourses">
                搜索
              </button>
            </div>
          </div>
        </div>
        <div class="hero-image">
          <!-- 使用CSS背景图片替代，通过CSS样式显示 -->
        </div>
      </div>
    </div>

    <!-- 筛选导航栏 - Udemy风格 -->
    <div class="filter-nav">
      <div class="container">
        <div class="filter-content">
          <!-- 分类标签 -->
          <div class="category-filters">
            <button 
              :class="['category-tab', { active: !searchParams.categoryId }]"
              @click="filterByCategory('')"
            >
              全部
            </button>
            <button 
              v-for="category in categories" 
              :key="category.id"
              :class="['category-tab', { active: searchParams.categoryId === category.id }]"
              @click="filterByCategory(category.id)"
            >
              {{ category.name }}
            </button>
          </div>
          
          <!-- 筛选器 -->
          <div class="filter-controls">
            <!-- 难度筛选 -->
            <el-select 
              v-model="searchParams.difficulty" 
              placeholder="难度" 
              class="filter-select"
              clearable
              @change="searchCourses"
            >
              <el-option label="初级" value="BEGINNER" />
              <el-option label="中级" value="INTERMEDIATE" />
              <el-option label="高级" value="ADVANCED" />
            </el-select>
            
            <!-- 课程状态 -->
            <el-select 
              v-model="statusFilter" 
              placeholder="课程状态" 
              class="filter-select"
              clearable
              @change="applyStatusFilter"
            >
              <el-option label="最新上线" value="latest" />
              <el-option label="热门推荐" value="popular" />
              <el-option label="已完结" value="completed" />
            </el-select>
            
            <!-- 排序 -->
            <el-select 
              v-model="sortBy" 
              placeholder="排序方式" 
              class="filter-select"
              @change="applySorting"
            >
              <el-option label="最受欢迎" value="popular" />
              <el-option label="最新发布" value="newest" />
              <el-option label="评分最高" value="rating" />
              <el-option label="注册人数最多" value="enrollment-high" />
              <el-option label="更新时间" value="updated" />
            </el-select>
          </div>
        </div>
      </div>
    </div>

    <!-- 课程统计 -->
    <div class="results-header">
      <div class="container">
        <div class="results-info">
          <h2 class="results-title">
            <template v-if="searchParams.keyword">
              "{{ searchParams.keyword }}" 的搜索结果
            </template>
            <template v-else-if="getSelectedCategoryName()">
              {{ getSelectedCategoryName() }} 课程
            </template>
            <template v-else>
              所有课程
            </template>
          </h2>
          <p class="results-count">共找到 {{ pagination.total || 0 }} 门课程</p>
        </div>
      </div>
    </div>

    <!-- 课程列表 -->
    <div class="courses-section">
      <div class="container">
        <!-- 加载状态 -->
        <div v-if="loading" class="loading-state">
          <div class="loading-spinner">
            <svg class="spinner" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor">
              <path d="M21 12a9 9 0 1 1-6.219-8.56"/>
            </svg>
          </div>
          <p class="loading-text">正在加载课程...</p>
        </div>
        
        <!-- 空状态 -->
        <div v-else-if="courses.length === 0" class="empty-state">
          <div class="empty-icon">
            <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor">
              <path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path>
              <path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path>
            </svg>
          </div>
          <h3 class="empty-title">暂无课程</h3>
          <p class="empty-subtitle">当前筛选条件下没有找到相关课程</p>
          <button class="reset-btn" @click="resetFilters">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
              <polyline points="23,4 23,10 17,10"></polyline>
              <polyline points="1,20 1,14 7,14"></polyline>
              <path d="M20.49 9A9 9 0 0 0 5.64 5.64l1.27 1.27m4.16 4.16l1.27 1.27A9 9 0 0 0 20.49 9z"></path>
            </svg>
            重置筛选
          </button>
        </div>
        
        <!-- 课程网格 - Udemy风格 -->
        <div v-else class="courses-grid">
          <div 
            v-for="course in courses" 
            :key="course.id" 
            class="course-card"
            @click="goToCourseDetail(course.id)"
          >
            <!-- 课程封面 -->
            <div class="course-image">
              <img 
                :src="getActualCoverUrl(course)" 
                :alt="course.title"
                @error="(e) => onCoverError(e, course)"
                class="cover-img"
              >
              <div class="course-overlay">
                <div class="overlay-content">
                  <button class="preview-btn" @click.stop="previewCourse(course)">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                      <polygon points="5,3 19,12 5,21"></polygon>
                    </svg>
                    预览课程
                  </button>
                  <button class="wishlist-btn" @click.stop="toggleWishlist(course)">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                      <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
                    </svg>
                  </button>
                </div>
              </div>
              <!-- 课程标签 -->
              <div class="course-badges">
                <span v-if="course.price === 0" class="badge free">免费</span>
                <span v-if="(course as any).isBestseller" class="badge bestseller">畅销课程</span>
                <span v-if="(course as any).isNew" class="badge new">新课程</span>
              </div>
            </div>

            <!-- 课程信息 -->
            <div class="course-info">
              <h3 class="course-title">{{ course.title }}</h3>
              <p class="course-description">{{ truncateText(course.description, 80) }}</p>
              <p class="course-instructor">{{ course.teacherName || '未知讲师' }}</p>
              
              <!-- 评分和评价 -->
              <div class="course-rating">
                <div class="rating-display">
                  <span class="rating-score">{{ (course.averageRating || 4.5).toFixed(1) }}</span>
                  <div class="stars">
                    <svg v-for="i in 5" :key="i" 
                         :class="['star', { filled: i <= Math.floor(course.averageRating || 4.5) }]" 
                         width="12" height="12" viewBox="0 0 24 24" fill="currentColor">
                      <polygon points="12,2 15.09,8.26 22,9.27 17,14.14 18.18,21.02 12,17.77 5.82,21.02 7,14.14 2,9.27 8.91,8.26"></polygon>
                    </svg>
                  </div>
                  <span class="rating-count">({{ course.reviewCount || 1234 }})</span>
                </div>
              </div>

              <!-- 课程标签 -->
              <div class="course-meta">
                <span class="meta-item">
                  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <circle cx="12" cy="12" r="10"></circle>
                    <polyline points="12,6 12,12 16,14"></polyline>
                  </svg>
                  {{ formatDuration((course as any).duration || 120) }}
                </span>
                <span class="meta-item">
                  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                    <circle cx="9" cy="7" r="4"></circle>
                    <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
                    <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
                  </svg>
                  {{ getDifficultyText(course.difficulty) }}
                </span>
              </div>

              <!-- 价格 -->
                              <div class="course-footer">
                <div class="free-learning-badge">
                  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
                  </svg>
                  免费学习
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 分页 -->
        <div v-if="courses.length > 0 && totalPages > 1" class="pagination-wrapper">
          <div class="pagination">
            <button 
              class="page-btn prev"
              :disabled="(searchParams.page || 1) <= 1"
              @click="changePage((searchParams.page || 1) - 1)"
            >
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <polyline points="15,18 9,12 15,6"></polyline>
              </svg>
              上一页
            </button>
            
            <div class="page-numbers">
              <button 
                v-for="page in visiblePages" 
                :key="page"
                class="page-number"
                :class="{ active: page === (searchParams.page || 1) }"
                @click="changePage(page)"
              >
                {{ page }}
              </button>
            </div>
            
            <button 
              class="page-btn next"
              :disabled="(searchParams.page || 1) >= totalPages"
              @click="changePage((searchParams.page || 1) + 1)"
            >
              下一页
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                <polyline points="9,18 15,12 9,6"></polyline>
              </svg>
            </button>
          </div>
          
          <div class="pagination-info">
            共 {{ total }} 门课程，第 {{ searchParams.page || 1 }} / {{ totalPages }} 页
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onMounted, watch } from 'vue'
import { useRouter } from 'vue-router'
import { courseApi, enrollmentApi, type Course, type Category, type CourseSearchParams } from '@/api/course'
import { ElMessage } from 'element-plus'

const router = useRouter()

// 状态管理
const courses = ref<Course[]>([])
const categories = ref<Category[]>([])
const total = ref(0)
const loading = ref(false)

// 新增状态
const statusFilter = ref('')
const sortBy = ref('popular')
const pagination = reactive({
  total: 0,
  page: 1,
  pageSize: 12
})

// 搜索参数
const searchParams = reactive<CourseSearchParams>({
  keyword: '',
  categoryId: undefined,
  difficulty: undefined,
  minPrice: undefined,
  maxPrice: undefined,
  sortBy: 'latest',
  page: 1,
  pageSize: 12
})

// 计算属性
const totalPages = computed(() => Math.ceil(total.value / (searchParams.pageSize || 12)))
const visiblePages = computed(() => {
  const current = searchParams.page || 1
  const total = totalPages.value
  const delta = 2
  
  let start = Math.max(1, current - delta)
  let end = Math.min(total, current + delta)
  
  if (end - start < delta * 2) {
    if (start === 1) {
      end = Math.min(total, start + delta * 2)
    } else {
      start = Math.max(1, end - delta * 2)
    }
  }
  
  return Array.from({ length: end - start + 1 }, (_, i) => start + i)
})

// 默认封面图片
const defaultCovers = {
  1: 'https://images.unsplash.com/photo-1627398242454-45a1465c2479?w=400&h=240&fit=crop',
  2: 'https://images.unsplash.com/photo-1561070791-2526d30994b5?w=400&h=240&fit=crop',
  3: 'https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=400&h=240&fit=crop',
  4: 'https://images.unsplash.com/photo-1434030216411-0b793f4b4173?w=400&h=240&fit=crop',
  default: 'https://images.unsplash.com/photo-1516321318423-f06f85e504b3?w=400&h=240&fit=crop'
}

// 方法
const loadCourses = async () => {
  loading.value = true
  try {
    console.log('🔄 加载课程列表，参数:', searchParams)
    const response = await courseApi.getCourses(searchParams)
    console.log('📚 课程数据:', response)
    
    if (response && response.content && Array.isArray(response.content)) {
      courses.value = response.content
      total.value = response.totalElements || response.content.length
    } else if (Array.isArray(response)) {
      courses.value = response
      total.value = response.length
    } else {
      courses.value = []
      total.value = 0
    }
    
    console.log(`✅ 成功加载 ${courses.value.length} 门课程，总计 ${total.value} 门`)
  } catch (error: any) {
    console.error('❌ 加载课程失败:', error)
    ElMessage.error(error.message || '加载课程失败')
    courses.value = []
    total.value = 0
  } finally {
    loading.value = false
  }
}

const loadCategories = async () => {
  try {
    console.log('🔄 加载课程分类...')
    const categoriesData = await courseApi.getCategories()
    categories.value = categoriesData || []
    console.log('📂 分类数据:', categories.value)
  } catch (error: any) {
    console.error('❌ 加载分类失败:', error)
    categories.value = [
      { id: 1, name: '前端开发', sortOrder: 1 },
      { id: 2, name: '后端开发', sortOrder: 2 },
      { id: 3, name: '移动开发', sortOrder: 3 },
      { id: 4, name: '数据科学', sortOrder: 4 }
    ] as any
  }
}

const searchCourses = () => {
  searchParams.page = 1
  loadCourses()
}

const filterByCategory = (categoryId?: string | number) => {
  searchParams.categoryId = categoryId === '' ? undefined : Number(categoryId) || undefined
  searchParams.page = 1
  loadCourses()
}

const resetFilters = () => {
  searchParams.keyword = ''
  searchParams.categoryId = undefined
  searchParams.difficulty = undefined
  searchParams.minPrice = undefined
  searchParams.maxPrice = undefined
  statusFilter.value = ''
  sortBy.value = 'popular'
  searchParams.page = 1
  loadCourses()
}

const changePage = (page: number) => {
  searchParams.page = page
  loadCourses()
  window.scrollTo({ top: 0, behavior: 'smooth' })
}

const goToCourseDetail = (courseId: number) => {
  console.log('🎯 跳转到课程详情:', courseId)
  router.push({ name: 'CourseDetail', params: { id: String(courseId) } })
}

const handleQuickEnroll = async (course: Course) => {
  try {
    await enrollmentApi.enrollCourse(course.id)
    ElMessage.success(`成功选课: ${course.title}`)
    course.enrollmentCount = (course.enrollmentCount || 0) + 1
  } catch (error: any) {
    if (error.message?.includes('已经选过')) {
      ElMessage.info('您已经选过这门课程了')
    } else {
      ElMessage.error(error.message || '选课失败')
    }
  }
}

// 工具方法
const getDefaultCover = (categoryId?: number) => {
  return defaultCovers[categoryId as keyof typeof defaultCovers] || defaultCovers.default
}

const getActualCoverUrl = (course: any) => {
  if (course.coverUrl) {
    if (course.coverUrl.startsWith('/uploads/')) {
      return `http://localhost:8080${course.coverUrl}`
    }
    return course.coverUrl
  }
  return getDefaultCover(course.categoryId)
}

const onCoverError = (e: Event, course: any) => {
  const target = e.target as HTMLImageElement
  target.src = getDefaultCover(course?.categoryId)
}

const getCategoryName = (categoryId?: number) => {
  const category = categories.value.find(c => c.id === categoryId)
  return category?.name || '其他'
}

const getDifficultyText = (difficulty?: string) => {
  const texts = { 
    BEGINNER: '初级', 
    INTERMEDIATE: '中级', 
    ADVANCED: '高级',
    EASY: '简单',
    MEDIUM: '中等',
    HARD: '困难'
  }
  return texts[difficulty as keyof typeof texts] || '中级'
}

const formatDuration = (duration?: number) => {
  if (!duration) return '未知'
  if (duration < 60) return `${duration}分钟`
  const hours = Math.floor(duration / 60)
  const minutes = duration % 60
  return minutes > 0 ? `${hours}小时${minutes}分钟` : `${hours}小时`
}

// 新增功能方法
const truncateText = (text: string, maxLength: number) => {
  if (!text) return ''
  if (text.length <= maxLength) return text
  return text.slice(0, maxLength) + '...'
}

const getSelectedCategoryName = () => {
  const category = categories.value.find(c => c.id === Number(searchParams.categoryId))
  return category?.name
}



const applyStatusFilter = () => {
  // 状态筛选逻辑，目前主要影响排序
  if (statusFilter.value === 'latest') {
    sortBy.value = 'newest'
  } else if (statusFilter.value === 'popular') {
    sortBy.value = 'popular'
  } else if (statusFilter.value === 'completed') {
    // 可以添加完结课程的特殊逻辑
    sortBy.value = 'rating'
  }
  searchParams.page = 1
  applySorting()
}

const applySorting = () => {
  searchParams.sortBy = sortBy.value
  searchParams.page = 1
  searchCourses()
}

const previewCourse = (course: Course) => {
  ElMessage.info('课程预览功能即将推出')
}

const toggleWishlist = (course: Course) => {
  ElMessage.success('已添加到收藏夹')
}



// 生命周期
onMounted(() => {
  console.log('🚀 课程列表页面初始化')
  loadCourses()
  loadCategories()
})
</script>

<style scoped>
/* Udemy风格的课程页面 */
.udemy-courses-page {
  min-height: 100vh;
  background: #fff;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 英雄区域 - Udemy风格 */
.hero-section {
  background: linear-gradient(135deg, #a855f7 0%, #3b82f6 100%);
  color: white;
  padding: 80px 0;
  position: relative;
  overflow: hidden;
}

.hero-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 60px;
  align-items: center;
}

.hero-content {
  z-index: 2;
}

.hero-title {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 16px;
}

.hero-subtitle {
  font-size: 20px;
  opacity: 0.9;
  margin-bottom: 32px;
  line-height: 1.5;
}

.hero-search {
  max-width: 500px;
}

.hero-search .search-container {
  position: relative;
  display: flex;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.hero-search .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #6b7280;
  z-index: 1;
}

.hero-search-input {
  flex: 1;
  padding: 16px 16px 16px 48px;
  border: none;
  font-size: 16px;
  outline: none;
}

.hero-search-input::placeholder {
  color: #9ca3af;
}

.hero-search-btn {
  padding: 16px 24px;
  background: #1f2937;
  color: white;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

.hero-search-btn:hover {
  background: #111827;
}

.hero-image {
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
}

.hero-image::before {
  content: '💻';
  font-size: 120px;
  opacity: 0.6;
  color: white;
}

/* 筛选导航栏 */
.filter-nav {
  background: white;
  border-bottom: 1px solid #e5e5e5;
  padding: 20px 0;
  position: sticky;
  top: 64px;
  z-index: 10;
}

.filter-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.category-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.category-tab {
  padding: 8px 16px;
  border: 1px solid #d1d5db;
  background: white;
  color: #374151;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.category-tab:hover {
  border-color: #6b7280;
}

.category-tab.active {
  background: #1f2937;
  color: white;
  border-color: #1f2937;
}

.filter-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.filter-select {
  min-width: 120px;
}

/* 结果页头 */
.results-header {
  background: #f9fafb;
  padding: 24px 0;
  border-bottom: 1px solid #e5e5e5;
}

.results-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-title {
  font-size: 24px;
  font-weight: 700;
  color: #111827;
  margin: 0;
}

.results-count {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

.search-controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.search-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  max-width: 500px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  z-index: 1;
}

.search-input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 48px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background: #f8f9fa;
  transition: all 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: #4A90E2;
  background: white;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.search-btn {
  height: 48px;
  padding: 0 24px;
  background: #4dc0b5;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s;
}

.search-btn:hover {
  background: #45a69b;
}

.filter-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 8px 16px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 20px;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tab:hover {
  border-color: #4A90E2;
  color: #4A90E2;
}

.filter-tab.active {
  background: #4A90E2;
  border-color: #4A90E2;
  color: white;
}

/* 课程区域 */
.courses-section {
  padding: 40px 0 80px;
}

/* 加载和空状态 */
.loading-state,
.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.loading-spinner {
  margin-bottom: 20px;
}

.spinner {
  color: #4A90E2;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: #666;
  font-size: 16px;
}

.empty-icon {
  margin-bottom: 20px;
  color: #999;
}

.empty-title {
  font-size: 24px;
  font-weight: 500;
  color: #333;
  margin-bottom: 12px;
}

.empty-subtitle {
  color: #666;
  margin-bottom: 30px;
}

.reset-btn {
  background: #4A90E2;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s;
}

.reset-btn:hover {
  background: #357ABD;
}

/* 课程区域 */
.courses-section {
  padding: 32px 0;
  background: white;
}

/* 课程网格 - Udemy风格 */
.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 32px 24px;
}

.course-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  position: relative;
  transition: all 0.3s;
}

.course-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.course-image {
  position: relative;
  height: 180px;
  overflow: hidden;
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.course-card:hover .cover-img {
  transform: scale(1.05);
}

.course-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.course-card:hover .course-overlay {
  opacity: 1;
}

.play-btn {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4A90E2;
}

.course-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255,255,255,0.9);
  color: #4A90E2;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

/* 课程信息区域 */
.course-info {
  padding: 16px;
}

.course-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-rating {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.stars {
  display: flex;
  gap: 2px;
}

.star {
  color: #e0e0e0;
  font-size: 14px;
}

.star.filled {
  color: #ffc107;
}

.rating-text {
  font-size: 12px;
  color: #666;
}

.course-description {
  color: #666;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #666;
  font-size: 12px;
}

.meta-item svg {
  color: #999;
}

.course-actions {
  display: flex;
  justify-content: flex-end;
}

.enroll-btn {
  background: #4dc0b5;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s;
}

.enroll-btn:hover {
  background: #45a69b;
}

/* 分页 */
.pagination-wrapper {
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-btn {
  background: white;
  border: 1px solid #ddd;
  color: #333;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
  border-color: #4A90E2;
  color: #4A90E2;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-numbers {
  display: flex;
  gap: 4px;
}

.page-number {
  width: 32px;
  height: 32px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.page-number:hover {
  border-color: #4A90E2;
  color: #4A90E2;
}

.page-number.active {
  background: #4A90E2;
  border-color: #4A90E2;
  color: white;
}

.pagination-info {
  color: #666;
  font-size: 14px;
}

/* 动画 */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .search-bar {
    flex-direction: column;
  }
  
  .search-input-wrapper {
    max-width: none;
  }
  
  .courses-grid {
    grid-template-columns: 1fr;
  }
  
  .filter-tabs {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 8px;
  }
  
  .filter-tab {
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .page-title {
    font-size: 24px;
  }
  
  .course-content {
    padding: 16px;
  }
  
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* 添加新的Udemy风格样式 */
.course-title {
  font-size: 16px !important;
  font-weight: 700 !important;
  color: #1f2937 !important;
  line-height: 1.4 !important;
  margin-bottom: 8px !important;
}

.course-description {
  font-size: 12px !important;
  color: #6b7280 !important;
  line-height: 1.4 !important;
  margin-bottom: 4px !important;
}

.course-instructor {
  font-size: 12px !important;
  color: #9ca3af !important;
  margin-bottom: 8px !important;
}

.rating-display {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  margin-bottom: 8px !important;
}

.rating-score {
  font-size: 14px !important;
  font-weight: 700 !important;
  color: #f59e0b !important;
}

.stars {
  display: flex !important;
  gap: 2px !important;
}

.star {
  color: #d1d5db !important;
}

.star.filled {
  color: #f59e0b !important;
}

.rating-count {
  font-size: 12px !important;
  color: #6b7280 !important;
}

.course-footer {
  padding: 16px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: center;
}

.free-learning-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}

.free-learning-badge svg {
  color: white;
}

.current-price {
  font-size: 16px !important;
  font-weight: 700 !important;
  color: #1f2937 !important;
}

.current-price.free {
  color: #10b981 !important;
}

.original-price {
  font-size: 14px !important;
  color: #9ca3af !important;
  text-decoration: line-through !important;
}
</style>